import React from 'react';
import ReactDOM from 'react-dom';
import App from './demo/reactredux';
import { Provider } from 'react-redux';
import { JQ } from './model/demo1';
import { createStore, applyMiddleware, combineReducers } from 'redux';
import thunk from 'redux-thunk';
// react router 4
import { BrowserRouter, Switch, Route, Link } from 'react-router-dom';
import Lq from './demo/test';

// 测试同名action
import { samea, doAdd, doDel } from './model/samea';
import { samea as sameb, doAdd as da, doDel as dd } from './model/sameb';

const s2 = createStore(combineReducers({samea,sameb}), applyMiddleware(thunk));
s2.subscribe(()=>{
    console.log(s2.getState())
})
setTimeout(()=>{
    s2.dispatch(doAdd());
},3000)
console.log(s2.getState());

const store = createStore(JQ, applyMiddleware(thunk));

ReactDOM.render((
<Provider store={store}>
    <BrowserRouter>
        <div>
            <p><Link to="/a">a</Link></p>
            <p><Link to="/b">b</Link></p>
            <p><Link to="/c">c</Link></p>
            <Route exact path="/" component={Lq} />
            <Route path="/b" component={page2} />
            <Route path="/c" component={page3} />
            <Route path="/:x" exact render={({history, location, match})=>{
                console.log(history, location, match);
                return <div>test<input type="button" value="tt" onClick={()=>{history.push('/')}} /></div>
            }} />
            <App />
        </div>
    </BrowserRouter>
</Provider>
), document.getElementById('root'));

store.subscribe(()=>{
    console.log(store.getState())
})



function page1(){
    console.log(2222);
    return (<div>page1</div>)
}
function page2(){
    return (<div>page2</div>)
}
function page3(){
    return (<div>page3</div>)
}